const {
  selectUserInfo,
  selectUserListInfo,
  selectUser,
  selectUserInfoById,
  insertUser,
  getToken,
  getRefreshToken,
  updateUser,
  deleteUser
} = require('../service/user');

/* 获取用户信息 */
let getUsers = async (ctx, next) => {
  selectUserInfo(ctx, next);
};

let getUserList = async (ctx, next) => {
  selectUserListInfo(ctx, next);
};

/* 根据id获取用户信息 */
let getUser = async (ctx, next) => {
  selectUser(ctx, next);
};
/* 根据id获取用户信息 */
let getUserById = async (ctx, next) => {
  selectUserInfoById(ctx, next);
};
/* 保存用户信息 */
let saveUser = async (ctx, next) => {
  insertUser(ctx, next);
};
/* 登录 */
let login = async (ctx, next) => {
  getToken(ctx, next);
};
/* 刷新token */
let refreshToken = async (ctx, next) => {
  getRefreshToken(ctx, next);
};

/* 保存用户信息 */
let putUser = async (ctx, next) => {
  updateUser(ctx, next);
};

/* 保存用户信息 */
let delUser = async (ctx, next) => {
  deleteUser(ctx, next);
};

/* 注意请求方式后面的空格 */
module.exports = {
  'GET /organization/user/conditions': getUsers,
  'GET /organization/user': getUser,

  'GET /userInfo': getUserList,
  'GET /user/:id': getUserById,
  'POST /user': saveUser,
  'POST /oauth/token': login,
  'POST /oauth/refreshToken': refreshToken,
  'PUT /user/:id': putUser,
  'DELETE /user/:id': delUser,
};